<template>
  <a-card :bordered="false">
    <a-form ref="searchFormRef" name="advanced_search" :model="searchFormState" class="ant-advanced-search-form">
      <a-row :gutter="24">
        <a-col :span="8">
          <a-form-item label="时间" name="timer">
            <a-range-picker v-model:value="searchFormState.timer" show-time valueFormat="YYYY-MM-DD HH:mm:ss"/>
          </a-form-item>
        </a-col>
        <a-col :span="6">
          <a-form-item label="部门" name="sector">
            <a-select v-model:value="searchFormState.sector">
              <a-select-option :value="1">技师</a-select-option>
              <a-select-option :value="2">楼面</a-select-option>
            </a-select>
          </a-form-item>
        </a-col>
        <a-col :span="6">
          <a-button type="primary" @click="table.refresh(true)">查询</a-button>
          <a-button style="margin: 0 8px" @click="reset">重置</a-button>
        </a-col>
      </a-row>
    </a-form>
    <s-table ref="table" :columns="columns" :data="loadData" :alert="options.alert.show" bordered
      :row-key="(record) => record.id" :tool-config="toolConfig" :row-selection="options.rowSelection">
      <template #bodyCell="{ column, record }">
        <template v-if="column.dataIndex === 'categoryName'">
          {{ categoryIdOptions.filter(v => v.id == record.categoryId)[0].categoryName || '' }}
        </template>
        <template v-if="column.dataIndex === 'action'">
          <a-space>
            <a @click="formRef.onOpen(record)" v-if="hasPerm('bizGoodsEdit')">编辑</a>
            <a-divider type="vertical" v-if="hasPerm(['bizGoodsEdit', 'bizGoodsDelete'], 'and')" />
            <a-popconfirm title="确定要删除吗？" @confirm="deleteBizGoods(record)">
              <a-button type="link" danger size="small" v-if="hasPerm('bizGoodsDelete')">删除</a-button>
            </a-popconfirm>
          </a-space>
        </template>
      </template>
    </s-table>
  </a-card>
</template>

<script setup name="goods">
import bizAttendanceApi from '@/api/biz/bizAttendanceApi'
let searchFormState = reactive({
  sector: '',
  endBeganTime: '',
  startBeganTime: '',
  timer: [],
})
const categoryIdOptions = ref([])
const searchFormRef = ref()
const table = ref()
const toolConfig = { refresh: true, height: true, columnSetting: true, striped: false }
const columns = [
  {
    title: '部门',
    dataIndex: 'sector'
  },
  {
    title: '工号',
    dataIndex: 'jobNo'
  },
  {
    title: '姓名',
    dataIndex: 'userName'
  },
  {
    title: '打卡类型',
    dataIndex: 'absenteeism'
  },
  {
    title: '打卡时间',
    dataIndex: 'total'
  },
]
const selectedRowKeys = ref([])
// 列表选择配置
const options = {
  // columns数字类型字段加入 needTotal: true 可以勾选自动算账
  alert: {
    show: true,
    clear: () => {
      selectedRowKeys.value = ref([])
    }
  },
  rowSelection: {
    onChange: (selectedRowKey, selectedRows) => {
      selectedRowKeys.value = selectedRowKey
    }
  }
}
const loadData = (parameter) => {
  const searchFormParam = JSON.parse(JSON.stringify(searchFormState))
  return bizAttendanceApi.bizAttendanceQueryReport(Object.assign(parameter, searchFormParam)).then((data) => {
    return data
  })
}
// 重置
const reset = () => {
  searchFormRef.value.resetFields()
  table.value.refresh(true)
}
</script>